package com.serita.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ExpandableListView;

import com.serita.demo.adapter.MinePrizeResultAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class QQActivity extends AppCompatActivity {
    private List<String> groupData;
    private List<List<String>> childrenData;
    @InjectView(R.id.elv)
    ExpandableListView mElv;
    private MinePrizeResultAdapter mMinePrizeResultAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qq);
        ButterKnife.inject(this);
        initView();
        initData();
        initListener();
    }

    private void initListener() {
//        mElv.setOnGroupClickListener(new OnGroupClickListener() {
//            @Override
//            public boolean onGroupClick(ExpandableListView parent, View clickedView, int groupPosition, long groupId) {
//                showMessage("点击Group: " + ((TextView)clickedView).getText());
//                return false;//返回true表示此事件在此被处理了
//            }
//        });
//        expandableListView.setOnChildClickListener(new OnChildClickListener() {
//            @Override
//            public boolean onChildClick(ExpandableListView expandablelistview,
//                                        View clickedView, int groupPosition, int childPosition, long childId) {
//                showMessage("点击Child: " + ((TextView)clickedView).getText());
//                return false;//返回true表示此事件在此被处理了
//            }
//        });
//        expandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
//            @Override
//            public void onGroupCollapse(int groupPosition) {
//                showMessage("合拢Group: " + (groupPosition + 1));
//            }
//        });
//        expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {
//            @Override
//            public void onGroupExpand(int groupPosition) {
//                showMessage("展开Group: " + (groupPosition + 1));
//            }
//        });
//    }
}

    private void initData() {
            groupData = new ArrayList<String>();
            groupData.add("Group 1");
            groupData.add("Group 2");
            groupData.add("Group 3");

            childrenData = new ArrayList<List<String>>();
            List<String> sub1 = new ArrayList<String>();
            sub1.add("G1 Item 1");
            sub1.add("G1 Item 2");
            childrenData.add(sub1);
            List<String> sub2 = new ArrayList<String>();
            sub2.add("G2 Item 1");
            sub2.add("G2 Item 2");
            sub2.add("G2 Item 3");
            sub2.add("G2 Item 4");
            childrenData.add(sub2);
            List<String> sub3 = new ArrayList<String>();
            sub3.add("G3 Item 1");
            sub3.add("G3 Item 2");
            sub3.add("G3 Item 3");
            sub3.add("G3 Item 4");
            sub3.add("G3 Item 5");
            childrenData.add(sub3);
        mMinePrizeResultAdapter = new MinePrizeResultAdapter(this,childrenData,groupData);
        mElv.setAdapter(mMinePrizeResultAdapter);
        expandGroup();
    }

    private void initView() {
        View headView = View.inflate(this, R.layout.contact_head, null);
        mElv.addHeaderView(headView);
    }
    public void expandGroup(){
        //设置所有组默认展开
        for(int i=0;i<groupData.size();i++){
            mElv.expandGroup(i);
        }
//        mElv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
//            @Override
//            public boolean onGroupClick(ExpandableListView parent, View v,
//                                        int groupPosition, long id) {
//            //设置点击不关闭（不收回）
//                v.setClickable(true);
//                return true;
//            }
//        });
    }
}
